<template>
  <div>
    <!--搜索查询-->
    <el-row>
      <!-- <el-col :span="">&nbsp;</el-col> -->
      <el-col :span="4"
        ><el-input
          v-model="searchForm.loginName"
          size="mini"
          clearable
          placeholder="请输入登录账号"
        ></el-input
      ></el-col>
      <el-col :span="2"
        ><el-button
          type="primary"
          size="mini"
          @click="search()"
          icon="el-icon-search"
          >搜索</el-button
        ></el-col
      >
      <!--v-has="'dictData:search'"-->
      <el-col :span="2"
        ><el-button
          type="primary"
          size="mini"
          @click="flush()"

          icon="el-icon-refresh"
          >刷新</el-button
        ></el-col
      >
      <!--v-has="'dictData:flush'"-->
    </el-row>
    <el-row>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column
          prop="loginName"
          label="登录账号"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="ipaddr"
          label="登录ip地址"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="browser"
          :formatter="type"
          label="浏览器类型"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="os" 
          width="120"
          label="操作系统"
        >
        </el-table-column>
        <el-table-column
          prop="status" 
          width="80"
          :formatter="status"
          label="状态"
        >
        </el-table-column>
        <el-table-column
          prop="msg" 
          width="120"
          label="提示信息"
        >
        </el-table-column>
        <el-table-column
          prop="loginTime" 
          width="180"
          label="登录时间"
        >
        </el-table-column>
        

      </el-table>
    </el-row>
    <el-row>
      <!--分页插件-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 3, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>

  </div>
</template>

<script>
export default {
  data() {
    return {
      condition:"",
      data: [], //权限树数组对象
      tableData: [],
      currentPage: 1, //页码 第几页
      pageSize: 5, //每页显示数量
      total: 100, //总条数
      searchForm: {}, //搜索form表单
      form: {}, //form表单对象
    };
  },
  created() {
    //初始化方法 类似于jquery  $({})
    this.loadData();
  },
  //所有函数
  methods: {
    //加载数据
    loadData() {
      var _this = this;
      //复制 $http官网代码
      // var token  = localStorage.getItem("token");
      _this.$http
      this.$http.post("/system/loginlog/loginlog?currentPage="+this.currentPage+"&pageSize="+this.pageSize,this.searchForm).then(response=>{
          if (response.data.code == 2000) {
            console.log(response)
            _this.tableData = response.data.data.list;
            _this.total = response.data.data.total;
            //_this.options = response.data.data.list;
          }
        })
        .catch(function (error) {
          console.log(error);
          _this.$message.error("你错了。。。");
        });
    },
   
    //处理每页数量发生变化
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`);
      //让每页数量发生变化
      this.pageSize = val;
      //重载数据
      this.loadData();
    },
    //处理当前页变化
    handleCurrentChange(val) {
      //console.log(`当前页: ${val}`);
      //让每页数量发生变化
      this.currentPage = val;
      //重载数据
      this.loadData();
    },
    //查询
    search() {
      this.loadData();
    },
    //刷新
    flush() {
      location.reload();
    },
    //格式化方法
    status(row, column, cellValue, index) {
      return cellValue == 0 ? "异常" : "正常";
     
    },
    type(row, column, cellValue, index) {
      if(cellValue.toLowerCase().indexOf("msie") >= 0) {
        return "IE";  //判断是否为IE浏览器
      }else if(cellValue.toLowerCase().indexOf("firefox") >= 0) {
        return "Firefox"; //是否为Firefox浏览器
      }else if(cellValue.toLowerCase().indexOf("chrome") >= 0) {
        return "Chrome";  //是否为Chrome浏览器
      }else if(cellValue.toLowerCase().indexOf("opera") >= 0) {
        return "Opera";  //是否为Opera浏览器
      }else if(cellValue.toLowerCase().indexOf("safari") >= 0) {
        return "Safari";  //是否为Safari浏览器
      }else {
        return "未知";
      }
    }

  },
};
</script>